//
//  JXHBaseTableViewController.swift
//  JXHSinaWeiBo
//
//  Created by juxiaohui on 16/10/14.
//  Copyright © 2016年 juxiaohui. All rights reserved.
//

import UIKit

class JXHBaseTableViewController: UITableViewController {

    var islogin = JXHUserAcccountTool.shareInstance.isLogin()
    
    lazy var  visitorView = JXHVisitorView.visitorView()
    
    override func loadView() {
        
//        // 从沙盒中读取归档信息
//        var accontPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).last!
//        accontPath = (accontPath as NSString).appendingPathComponent("accont.plist")
//        
//        //取出数据
//        let accont = NSKeyedUnarchiver.unarchiveObject(withFile: accontPath) as? JXHUserAccontModel
//        
//        if let accont = accont {
//            
//            //取出过期日期
//           if let exporesDate = accont.expiresDate {
//
//           islogin =  exporesDate.compare(Date()) == ComparisonResult.orderedDescending
//            }
//        }
        
        islogin ? super.loadView() : setupVisitorView()
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        setupNavItems()
    }
}

extension JXHBaseTableViewController {
    
    func setupVisitorView()  {
        view  = visitorView
        visitorView.registBtn.addTarget(self, action: #selector(JXHBaseTableViewController.registBtnClick), for: .touchUpInside)
        visitorView.loginBtn.addTarget(self, action: #selector(JXHBaseTableViewController.logintBtnClick), for: .touchUpInside)
    }
    
    // MARK: - 设置导航栏Item

    func setupNavItems() {
    
        navigationItem.leftBarButtonItem = UIBarButtonItem.init(title: "注册", style: .plain, target: self, action: #selector(JXHBaseTableViewController.registBtnClick))
        
        navigationItem.rightBarButtonItem = UIBarButtonItem.init(title: "登录", style: .plain, target: self, action: #selector(JXHBaseTableViewController.logintBtnClick))
    }
}

// MARK: - 时间监听
extension JXHBaseTableViewController {

    func registBtnClick() {
    
        print("registBtnClick")
    }
    
    func logintBtnClick() {
        
        let oauthVc = JXHOAuthViewController()
        
        let oauthNav = UINavigationController.init(rootViewController: oauthVc)
        
        present(oauthNav, animated: true, completion: nil)
        
    }
}
